package com.zzz.algorithm;

import org.junit.Test;

public class HanoiStatus {
    private int n = 5;
    char from = 'A', to = 'C', temp = 'B';

    public int calcStatusIndexOf(String status, char from, char to, char temp, int n) {

        if (n == 0) {
            return 0;
        }
        //最后个盘子(最大盘子)位置
        char c = status.charAt(n - 1);
        if (c == temp) {//最大盘子不可能位于辅助盘子
            return -1;
        } else if (c == to) {
            int num = calcStatusIndexOf(status, temp, to, from, n - 1);
            return (1 << (n - 1)) + num;
        }
        return calcStatusIndexOf(status, from, temp, to, n - 1);
    }

    @Test
    public void test() {
        String status = "CCCCC";
        int num = calcStatusIndexOf(status, from, to, temp, n);
        System.out.println(num);
    }

}
